<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>Contractor Expiration Date Review</title>
<meta name="keywords" content="" />
<meta name="description" content="" />
<link href="../../CSS/default.css" rel="stylesheet" type="text/css" />
</head>

<cfinclude template="../../functions.cfm">
<cfinclude template="../../authentication.cfm">

<cfobject type="dotnet" name="objQuery" class="ADTools.Query" assembly ="C:\Program Files\Southcentral Foundation\ADTools\ADTools.dll"> 
<cfobject type="dotnet" name="objModify" class="ADTools.Modify" assembly ="C:\Program Files\Southcentral Foundation\ADTools\ADTools.dll">  

<cfset bolTermReq = False>

<cfif isdefined("Form.txtSubmit")>
	<!--- Check Form for required action --->
	
	<!--- Loop through all form elements and processes selected contractors --->
	<cfloop index="objField" list="#FORM.FieldNames#" DELIMITERS=",">
		
		<cfif left(objField,3) EQ "rdo" And Form[objField] EQ 1>
			<!--- Extend the expiration date for one month --->	
			<cfset strUserID = ListGetAt(right(objField, len(objField)-3),1,"|")>
			<cfset strExpDate = ListGetAt(right(objField, len(objField)-3),2,"|")>	
			
			<!---cfset strNewDate = DateFormat(dateAdd("d",-1,dateAdd("m", 1, strExpDate)), "mm/dd/yyyy")--->
			<cfset strNewDate = DateFormat(dateAdd("m", 1, strExpDate), "mm/dd/yyyy")>
			  
			<cfset strDN = objQuery.GetProperty("distinguishedName", "10.100.1.101", #strUserID#,"","")>
							
			<cfset objModify.init("10.100.1.101")>
			<cfset lngResult = objModify.SetAccountExpirationDateCF(#strDN#, "#strNewDate# 1:00:00 AM")>
		
		<cfelseif left(objField,3) EQ "rdo" And Form[objField] EQ 2>
			<!--- Send a termination notice to the service desk --->
			<cfset strUserID = ListGetAt(right(objField, len(objField)-3),1,"|")>
		
			<!--- Email type changed to text from html because Cherwell does not accept html emails --->
			<!---cfmail to="helpdesk@scf.cc;#Session.arrEmpInfo.Email#" from="#Session.arrEmpInfo.Email#" bcc="bfrick@scf.cc" subject="Archive User Request from Manager, #Session.arrEmpInfo.FullName#" type="html">
				Service Desk,<BR /><BR />				
				Please archive the following account:<BR /><BR />
				#strUserID#<BR /><BR /><br />
				NOTE:  This is an automated message sent on the behalf of #Session.arrEmpInfo.FullName#.  Please contact this manager directly with any questions regarding processing of this request.
			</cfmail--->
			
			<!--- NOTE: Cherwell will not accept the message if there is more than one recipient specified in the 'TO' field. --->
			<cfmail to="helpdesk@scf.cc" cc="#Session.arrEmpInfo.Email#" from="#Session.arrEmpInfo.Email#" bcc="SCFAppNotifyAdmin@scf.cc" subject="Archive User Request from Manager, #Session.arrEmpInfo.FullName#, to disable #strUserID#" type="html">
				Service Desk,<BR /><BR />
								
				Please archive the following account:<BR />
				
				#strUserID#<BR /><BR />
				
				NOTE:  This is an automated message sent on the behalf of #Session.arrEmpInfo.FullName#.  Please contact this manager directly with any questions regarding processing of this request.
			</cfmail>
			
			<cfset bolTermReq = True>
		</cfif>
		
	</cfloop>		
		
</cfif>


<cfset strDN = "">

<!--- Check first for the employees listed in AD as their direct hires --->    

<cfset lngResult = objQuery.ConnectToLDAP("10.100.1.101")>
<!---cfset strDN = objQuery.GetProperty("distinguishedName", "10.100.1.101", "#Session.strUserID#","","")--->
<cfset strDN = objQuery.GetProperty("distinguishedName", "10.100.1.101", "", "#Session.arrEmpInfo.AD_GUID#","")>
<!---cfset strDN = objQuery.GetProperty("distinguishedName", "10.100.1.101", "csmith","","")--->

<!--- LDAP required that certain characters be "escaped".  The escape character is "\".  This list is characters that do NOT need to be esacaped.  All others should be escaped. 
* ( ) . & - _ [ ] ' ~ | @ $ % ^ & ? : |
--->

<cfset strDN = replace(replace(replace(strDN, "\", "\\", "all"), ",", "\,", "all"), "=", "\=", "all")>


<cfldap 
	action="query" 
	attributes="displayname, sAMAccountName, manager" 
	filter="(&(objectclass=user)(manager=#strDN#))"
	username="userlist" 
	password="DefinedMan" 
	name="qrySubordinates" 
	sort="displayname"
	start="OU=SCFUsers,DC=Southcentralfoundation,DC=COM" 
	server="10.100.1.8">
	
    
    <cfoutput>
    <!-- start header -->
        <cfinclude template="../header.cfm"/>
    <!-- end header -->
    
    <!-- start page -->
    <div id="page">	
        <!-- start content -->
        <div class="content">
            <div class="post">
				<BR />
                <h1 class="title">Contractor Expiration Date Extension</h1>
                <div class="entry">    
                	 Welcome, <strong>#Session.arrEmpInfo.FullName#</strong>.&nbsp;&nbsp;On this page, you'll be allowed to extend the expiration date for those contractors that directly report to you.&nbsp;&nbsp;Accounts will expire at the end of every month.&nbsp;&nbsp;To extend the operating window for an additional month, select the option in the "Extend" column.&nbsp;&nbsp;There is a two week window prior to the end of each month where this option will be available to you.&nbsp;&nbsp;If the contractor is no longer with SCF, please select the "Terminate" option.&nbsp;&nbsp;If there are additional contractors that report directly to you that are not represented here, please contact the Service Desk at x5200. <br /><br />       
               
			   
                <cfform name="frmExpiration" method="post">
					<cfinput type="hidden" name="txtSubmit" value="Submission Validation">
                <table align="center">
					<cfset arrContractor = ArrayNew(2)>
					<cfset arrSCF = ArrayNew(2)>
					
					<cfloop query="qrySubordinates"> 
						<cfset strGUID = "">
						<cfset strExpDate = "Never">
						<cfset bolContractor = False>	
						<cfset bolDisabled = False>
						
						<cfquery name="qryGetGUID" datasource="RosettaStone">
							scf_GetRosettaInfo '#sAMAccountName#'
						</cfquery>
						<cfif qryGetGUID.recordcount GT 0>
							<cfset strGUID = qryGetGUID.AD_GUID>
							<cfset intNonSCFMasterID = qryGetGUID.NonSCFMasterID>
							<cfset intUserAccountControl = objQuery.GetProperty("useraccountcontrol", "10.100.1.101", "","#strGUID#","")>
		
							<cfif intUserAccountControl NEQ 546 AND intUserAccountControl NEQ 514 and intUserAccountControl NEQ 66050>
								<cfset bolDisabled = False>
								
								<cfif intNonSCFMasterID NEQ "">
									<cfset bolContractor = True>
									<cfset strExpDate = objQuery.GetAccountExpirationDate(#strGUID#, "10.100.1.101")>
									
									<cfif strExpDate EQ "1/1/1970 12:00:00 AM" OR Isnumeric(strExpDate) EQ 1>
										<cfset strExpDate = "Never">
									<cfelse>
										<cfset strExpDate = DateFormat(strExpDate, "mm/dd/yyyy")>
									</cfif>
									
								<cfelse>
									<cfset bolContractor = False>			
													
								</cfif>	
								
							<cfelse>
								<cfset bolDisabled = True>
							</cfif>
							
						<cfelse>
							<cfset bolDisabled = True>
													
							
						</cfif>
						
						<cfif Not bolDisabled>
							<cfif bolContractor>
								<cfset intIndex = ArrayLen(arrContractor) + 1>
								<cfset arrContractor[intIndex][1] = displayName>
								<cfset arrContractor[intIndex][2] = samAccountName>
								<cfset arrContractor[intIndex][3] = strExpDate>
								<cfif strExpDate EQ "Never">
									<cfset arrContractor[intIndex][4] = False>
								<cfelseif DateAdd("d", -14, strExpDate) GT Now()>
									<cfset arrContractor[intIndex][4] = False>
								<cfelse>
									<cfset arrContractor[intIndex][4] = True>
								</cfif>
							<cfelse>
								<cfset intIndex = ArrayLen(arrSCF) + 1>
								<cfset arrSCF[intIndex][1] = displayName>
								<cfset arrSCF[intIndex][2] = samAccountName>
								<cfset arrSCF[intIndex][3] = strExpDate>						
							</cfif>
						</cfif>
					</cfloop>
						
						
				   	<cfif bolTermReq>	
                	<tr>
                    	<td colspan="7">
							<span class="error">Your termination request has been sent to the Service Desk.<BR /></span>
						</td>
					</tr>
                	<tr>
                    	<td>&nbsp; </td>
					</tr>
				   	</cfif>			
                	<!---tr>
                    	<td>
                        	<strong>SCF Direct Hires Name</strong>
                        </td>
						<td>
							&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
						</td>
                    	<td>
                        	<strong>Expiration Date</strong>
                        </td>
						<td>
							&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
						</td>
                    	<td align="center">&nbsp;
                        	
                        </td>
						<td>
							&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
						</td>
                    	<td align="center">&nbsp;
                        	
                        </td>
                    </tr>
					<cfif ArrayLen(arrSCF) EQ 0>
					<tr>
                    	<td>						
                        	None
                        </td>
					</tr>
					<cfelse>
						<cfloop from=1 to=#ArrayLen(arrSCF)# index="intX">						
						<tr>
							<td>						
								#arrSCF[intX][1]#
							</td>
							<td>&nbsp;
								
							</td>
							<td>
								#arrSCF[intX][3]#
							</td>
							<td>&nbsp;
								
							</td>
							<td align="center">&nbsp;
								
							</td>
							<td>&nbsp;
								
							</td>
							<td align="center">&nbsp;
								
							</td>
						</tr>
						</cfloop>
					</cfif>
                	<tr>
                    	<td>&nbsp;
                        	
                        </td>
					</tr--->	
					<tr>
                    	<td>
                        	<strong>Contractor Name</strong>
                        </td>
						<td>
							&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
						</td>
                    	<td>
                        	<strong>Expiration Date</strong>
                        </td>
						<td>
							&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
						</td>
                    	<td align="center">
                        	<strong>Extend</strong>
                        </td>
						<td>
							&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
						</td>
                    	<td align="center">
                        	<strong>Terminate*</strong>
                        </td>
                    </tr>
					<cfif ArrayLen(arrContractor) EQ 0>
					<tr>
                    	<td>						
                        	None
                        </td>
					</tr>
					<cfelse>
						<cfloop from=1 to=#ArrayLen(arrContractor)# index="intX">						
						<tr>
							<td>
								#arrContractor[intX][1]#
							</td>
							<td>&nbsp;
								
							</td>
							<td>
								#arrContractor[intX][3]#
							</td>
							<td>&nbsp;
								
							</td>
							<td align="center">
								<cfif arrContractor[intX][4]>
									<cfinput type="radio" name="rdo#arrContractor[intX][2]#|#arrContractor[intX][3]#" value="1">
								<cfelse>
									<span class="error">N/A</span>
								</cfif>
							</td>
							<td>&nbsp;
								
							</td>
							<td align="center">
								<cfinput type="radio" name="rdo#arrContractor[intX][2]#|#arrContractor[intX][3]#" value="2">
							</td>
						</tr>
						</cfloop>
					</cfif>
                	<tr>
                    	<td>&nbsp;
                        	
                        </td>
					</tr>	
					<cfif ArrayLen(arrContractor) GT 0>
                    <tr>
                    	<td colspan="7" align="right">
                        	<cfinput type="button" name="cmdClear" value="Clear" onClick="ClearRadios()"><cfinput type="submit" name="cmdSubmit" value="Submit">
                        </td>
                    </tr>
                	<tr>
                    	<td>&nbsp;
                        	
                        </td>
					</tr>	
					</cfif>
                </table>
                </cfform> 
				<cfif ArrayLen(arrContractor) GT 0>  
                *NOTE:&nbsp;&nbsp;All termination requests are sent via email to the Service Desk.&nbsp;&nbsp;You will receive a copy of the email, but please allow one business day to complete the request.&nbsp;&nbsp;If immediate action is necessary, please call the Service Desk directly at x5200.
				</cfif>
                </div>
            </div>
        </div>
        <!-- end content -->
        
    </div>
    <!-- end page -->
        <cfinclude template="../../footer.cfm">
    </body>
    </cfoutput>
</html>

<script language="javascript">
	function ClearRadios()
	{	
		for (i=0; i < document.getElementById('frmExpiration').elements.length; i++) {
			 var x = document.getElementById('frmExpiration').elements[i];
			 if (x.type == 'radio') {
				if (x.checked == true) { 
					x.checked = false 
				}
			 }
			 
		}
	}
</script>
